<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author Cheng
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar>
        <a-button type="primary" @click="handleForm({})" v-auth="'inspectionmanag:inQuestPickupTask:edit'">
          <Icon icon="i-fluent:add-12-filled" /> {{ t('新增') }}
        </a-button>
      </template>
      <template #firstColumn="{ record }">
        <a @click="handleForm({ tid: record.tid })">
          {{ record.taskId }}
        </a>
      </template>
    </BasicTable>
    <InputForm @register="registerDrawer" @success="handleSuccess" />
    <BpmRuntimeTrace @register="registerTraceModal" />
  </div>
</template>
<script lang="ts" setup name="ViewsInspectionmanagInQuestPickupTaskList">
  import { unref } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { inQuestPickupTaskDelete, inQuestPickupTaskListData } from '/@/api/inspectionmanag/inQuestPickupTask';
  import { useDrawer } from '/@/components/Drawer';
  import { useModal } from '/@/components/Modal';
  import { BpmRuntimeTrace } from '/@/components/Bpm';
  import { FormProps } from '/@/components/Form';
  import InputForm from './form.vue';

  const { t } = useI18n('inspectionmanag.inQuestPickupTask');
  const { showMessage } = useMessage();
  const { meta } = unref(router.currentRoute);

  const getTitle = {
    icon: meta.icon || 'i-ant-design:book-outlined',
    value: meta.title || t('任务领取表管理'),
  };

  const searchForm: FormProps = {
    baseColProps: { md: 8, lg: 6 },
    labelWidth: 90,
    schemas: [
      {
        label: t(''),
        field: 'taskTypeName',
        fieldLabel:'taskTypeName',
        component: 'Select',
        componentProps: {
          placeholder: t('请输入任务类型名称'),
          api:'inQuestPickupTaskListData',
          params: {},
        }
      },
      {
        label: t(''),
        field: 'taskStatus',
        component: 'Select',
        componentProps: {
          placeholder: t('请选择任务状态'),
          options: [
            {label: t('已巡检'), value: '已巡检'},
            {label: t('未巡检'), value: '未巡检'},
          ]
        }
      },
      {
        label: t(''),
        field: 'enterpriseName',
        component: 'Input',
        componentProps: {
          placeholder: t('请输入企业名称'),
         },
      
      },
      {
        label: t(''),
        field: 'enterpriseName',
        component: 'Input',
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('任务类型名称'),
      dataIndex: 'taskTypeName',
      key: 'a.task_type_name',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('任务状态'),
      dataIndex: 'taskStatus',
      key: 'a.task_status',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('所属企业名称'),
      dataIndex: 'enterpriseName',
      key: 'a.enterprise_name',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('角色名称'),
      dataIndex: 'roleName',
      key: 'a.role_name',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('领取人姓名'),
      dataIndex: 'receptionHumanName',
      key: 'a.reception_human_name',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('创建时间'),
      dataIndex: 'addTime',
      key: 'a.add_time',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('完成时间'),
      dataIndex: 'finishTime',
      key: 'a.finish_time',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('任务反馈'),
      dataIndex: 'feedBack',
      key: 'a.feed_back',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('是否有隐患'),
      dataIndex: 'abnormal',
      key: 'a.abnormal',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('隐患数量'),
      dataIndex: 'abnormalTotal',
      key: 'a.abnormal_total',
      sorter: true,
      width: 130,
      align: 'left',
    },
  ];

  const actionColumn: BasicColumn = {
    width: 160,
    actions: (record: Recordable) => [
      {
        icon: 'i-clarity:note-edit-line',
        title: t('编辑任务领取表'),
        onClick: handleForm.bind(this, { tid: record.tid }),
        auth: 'inspectionmanag:inTaskCollection:edit',
      },
      {
        icon: 'i-ant-design:delete-outlined',
        color: 'error',
        title: t('删除任务领取表'),
        popConfirm: {
          title: t('是否确认删除任务领取表'),
          confirm: handleDelete.bind(this, record),
        },
        auth: 'inspectionmanag:inTaskCollection:edit',
        // ifShow: () => record.status == '9',
      },
      {
        icon: 'i-fluent:flowchart-20-regular',
        title: t('流程追踪'),
        onClick: handleTrace.bind(this, record),
        // ifShow: () => record.status != '9',
      },
    ],
  };

  const [registerTable, { reload }] = useTable({
    api: inQuestPickupTaskListData,
    beforeFetch: (params) => {
      return params;
    },
    columns: tableColumns,
    actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  const [registerDrawer, { openDrawer }] = useDrawer();

  function handleForm(record: Recordable) {
    openDrawer(true, record);
  }

  async function handleDelete(record: Recordable) {
    const params = { tid: record.tid };
    const res = await inQuestPickupTaskDelete(params);
    showMessage(res.message);
    handleSuccess(record);
  }

  function handleSuccess(record: Recordable) {
    reload({ record });
  }

  const [registerTraceModal, { openModal: traceModel }] = useModal();

  function handleTrace(record: Recordable) {
    traceModel(true, { formKey: '', bizKey: record.id });
  }
</script>
